package com.android.fragmentdemo
import android.os.Bundle
import com.android.fragmentdemo.adapters.TurnTableAdapter
import com.hengfoxwolf.commonbase.base.BaseActivity
import com.android.fragmentdemo.databeans.DataFactoryIp
import com.hengfoxwolf.commonbase.base.databeans.TurnTableItem
import com.android.fragmentdemo.databinding.ActivityTurntableBinding
import com.android.fragmentdemo.definervlayoutmanager.TurntableLayoutManager
import com.hengfoxwolf.commonbase.base.adapter.BaseRvAdapter2

class TurntableActivity : BaseActivity<ActivityTurntableBinding>() {

    override fun getLayoutId(): Int = R.layout.activity_turntable

    override fun init(savedInstanceState: Bundle?) {
        val mDataSet = DataFactoryIp.createTurnTableItemDataSet()

        val mAdapter = TurnTableAdapter()
//        val mAdapter = TurnTableAdapter2()

        mAdapter.setOnItemClickListener(object : BaseRvAdapter2.IOnItemClickListener<TurnTableItem> {
            override fun onItemClick(dataItem: TurnTableItem, position: Int, viewId: Int) {
               this@TurntableActivity.showToast(dataItem.content)
            }
        })

//        mAdapter.setOnItemClickListener(object : BaseRvAdapter3.IOnItemClickListener<TurnTableItem> {
//            override fun onItemClick(dataItem: TurnTableItem, position: Int, viewId: Int) {
//               this@TurntableActivity.showToast(dataItem.content)
//            }
//        })

        mAdapter.itemDataSet = mDataSet
        //mAdapter.itemDataSet = null
        mBinding.rvTurntable.apply {
            layoutManager = TurntableLayoutManager(this@TurntableActivity, 15.0f)
            adapter = mAdapter
        }

//        Handler(Looper.getMainLooper()).postDelayed(
//            {
//                mAdapter.removeItemDataSet()
//                Log.d(TAG,"itemSizeXXX:${mAdapter.itemDataSet?.size}")
//            },
//            5000)

//        Handler(Looper.getMainLooper()).postDelayed(
//            {
//                mAdapter.addItemData(TurnTableItem(R.color.color_00E5FF,"H1"))
//                mAdapter.addItemData(TurnTableItem(R.color.color_D32F2F,"H7"))
//            },
//            10000)
    }

    companion object {
        const val TAG = "TurntableActivity"
    }
}